//
//  XLSView.m
//  yonghu
//
//  Created by mac on 2018/3/19.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "XLSView.h"
#import "XLSTableViewCell.h"
#import "OKViewController.h"
@implementation XLSView
-(void)creatView{
    _selectArr=[NSMutableArray arrayWithCapacity:0];
    _tableView =[UITableView new];
    [self addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(NAV_HEIGHT);
    }];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.backgroundColor=_LightGrey;
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

    NSString *str=@"温馨提示：以下是平台更绝您的需求提供的律师,您可以选择两个意向律师，平台将优先制定你的意向律师为您办案，如不选择视为平台指派。依法律规定，平台指派1-2名律师为你服务";
    CGSize size=[ZQTools getNSStringSize:str andViewWight:_mainW-30 andFont:16];

    UIView *headView=[UIView new];
    [headView setFrame:CGRectMake(0, 0,_mainW ,size.height+40)];
    headView.backgroundColor=_LightGrey;
    _tableView.tableHeaderView=headView;

    UILabel *label=[UILabel new];
    [headView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
        make.width.mas_equalTo(_mainW-15);
    }];
    label.numberOfLines=0;
    label.text=str;
    label.font=[UIFont systemFontOfSize:16];
    label.textColor=_backgroundColor;

    UIView *headView2=[UIView new];
    [headView2 setFrame:CGRectMake(0, 0,_mainW ,200)];
    headView2.backgroundColor=_LightGrey;
    _tableView.tableFooterView=headView2;

    UIButton *btn=[UIButton new];
    [headView2 addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
        make.width.mas_equalTo(_mainW-30);
        make.height.mas_equalTo(45);
    }];
    [btn setTitle:@"提交" forState:0];
    [btn setTitleColor:[UIColor whiteColor] forState:0];
    btn.layer.cornerRadius=10;
    btn.backgroundColor=_backgroundColor;
    [btn addTarget:self action:@selector(tijiao:) forControlEvents:UIControlEventTouchUpInside];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _tableArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    XLSTableViewCell *cell=[[XLSTableViewCell alloc] init];
    cell.row = indexPath.row;
    cell.dic=_tableArr[indexPath.row];
    
    __weak typeof(self) weakSelf = self;
    cell.customSelectedBlock = ^ (BOOL selected, NSInteger row)
    {
        if (selected) {
            if (_selectArr.count>=2) {
                [ZQTools svpInfo:@"最多只能选择两个律师"];
            }
            else{
                [_selectArr addObject:_tableArr[indexPath.row]];
            }
            
            
        }else
        {
            [_selectArr removeObject:_tableArr[indexPath.row]];
            
        }
    };
    
    [cell cretView];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 130;
}
-(IBAction)tijiao:(id)sender{
    NSMutableArray *typeArr=[NSMutableArray arrayWithCapacity:0];
    for (int i=0; i<_selectArr.count; i++) {
        NSDictionary *typeDic=_selectArr[i];
        NSNumber *waiter_id1=[typeDic objectForKey:@"waiter_id"];
        NSString *waiter_id=[NSString stringWithFormat:@"%@",waiter_id1];
        [typeArr addObject:waiter_id];
    }
    NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithDictionary:_dic];
    [dict setObject:typeArr forKey:@"lawyer_ids"];
    [ZQTools AFNPostDataUrl:@"user/litigation/send_litigation" Dict:dict andTableView:nil andViewController:self.viewController andSuccessBlock:^(id responseObject) {
        OKViewController *okView=[[OKViewController alloc] init];
        okView.dic=[NSDictionary dictionaryWithObjectsAndKeys:responseObject,@"litigation_id",@"发布案件",@"neixin", nil];
        [ZQTools pushNextViewController:self.viewController andRootController:okView];
    } anderrorBlock:nil];
    
}
@end
